package com.ruantu.clothing.controller;

import com.ruantu.clothing.entity.JsonResponseMessage;
import com.ruantu.clothing.entity.User;
import com.ruantu.clothing.entity.ZkSeason;
import com.ruantu.clothing.service.ZkSeasonService;
import com.ruantu.clothing.util.MyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by Administrator on 2018/7/26 0026.
 */
@Controller
@RequestMapping("/zkseason")
public class ZkSeasonController {
    private static final Logger logger = LoggerFactory.getLogger(ChuKuController.class);
    @Autowired
    private ZkSeasonService zkSeasonService;

    @RequestMapping("/lsit")
    @ResponseBody
    public JsonResponseMessage findList(HttpSession session) {
        JsonResponseMessage jsonResponseMessage = new JsonResponseMessage();
        User user = (User) session.getAttribute("info");
        jsonResponseMessage.setRows(zkSeasonService.findListZhekou(user.getJgid()));
        return jsonResponseMessage;
    }

    @RequestMapping("/save")
    @ResponseBody
    public JsonResponseMessage saveSeason(ZkSeason zkSeason, HttpSession session) {
        JsonResponseMessage jsonResponseMessage = new JsonResponseMessage();
        User user = (User) session.getAttribute("info");
        try {
            zkSeason.setJgId(user.getJgid());
            zkSeasonService.saveZk(zkSeason);
            jsonResponseMessage.setCode(200);
        } catch (MyException e) {
            logger.error(e.getMessage(), e);
            jsonResponseMessage.setCode(400);
            jsonResponseMessage.setMsg(e.getMessage());
        } catch (NullPointerException e) {
            logger.error(e.getMessage(), e);
            jsonResponseMessage.setCode(400);
            jsonResponseMessage.setMsg("服务器连接已断开，请重新登录进行尝试");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            jsonResponseMessage.setCode(400);
            jsonResponseMessage.setMsg("服务器连接已断开，请重新登录进行尝试");
        }
        return jsonResponseMessage;
    }


}
